import string
from random import choice
import optparse

"""
Generates files of random characters of a given length.
"""
def generateFile(size, name):

  # Open the file
  file = open(name, "w")
  
  # Generate our chars
  chars = string.letters + string.digits

  for i in range(size):
    c = choice(chars)
    file.write(c)
  file.close()

if __name__ == "__main__":

  # Set up the command line option parser
  usage = "generate_file.py --files <count> --file-length <length>"
  parser = optparse.OptionParser(usage)
  
  parser.add_option("-f", "--files", dest = "num_files", type = "int",
  		help = "Number of files.", default = 5, action = "store")
  
  parser.add_option("-l", "--file-length", dest = "file_len", type = "int",
		help = "Length of files.", default = 1024, action = "store")
  
  parser.add_option("-p", "--file-prefix", dest = "file_prefix", type = "string",
                    help = "File prefix.", default = "file", action = "store")

  parser.add_option("-s", "--file-suffix", dest = "file_suffix", type = "string",
                    help = "File suffix.", default=".txt", action = "store")

  options, args = parser.parse_args()
  
  for f in range(options.num_files):
    generateFile(options.file_len, options.file_prefix + str(f) + options.file_suffix)

    
